<?php

/*
 * Action 3$
 * 
 * +1 Action
 * Reveal cards from the top of your deck until you reveal one costing 3 Coin or more. Put that card into your hand and discard the rest.
 *
 */

class Sage extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Sage", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Action",
            "Reveal cards from the top of your deck until you reveal one costing 3$ or more",
            "Put that card into your hand and discard the rest.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action", "gets +1 action");
        //only looking on the top card
        $card = $game->peekCardFromDrawDeck();
        $discardCards = array();
        $good_card = null;
        while ($card != null) {
            $price = $card->getPrice($game);
            if ($price->compare(3) >= 0) {
                $good_card = $game->drawCards(1);
                break;
            } else {
               $card = $game->removeCardFromDrawDeck();
               $discardCards[] = $card;
            }             
             $card = $game->peekCardFromDrawDeck();
        }
        $game->discardTempDiscardCards($discardCards);
         ScreenDisplay::addScreenMessage($game, true, "reveal ".  nicePrint($discardCards). " and put ".  nicePrint($good_card). " in your hand", 
                "reveals ".  nicePrint($discardCards). " and puts ".  nicePrint($good_card). " in his hand");
        $game->cardActionFinished();
        return true;
    }

}

?>